<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h3>@keyup.enter → 监听键盘回车事件</h3>
      <input v-model="username" type="text" @keyup.enter="onKeyUp" />
      <!-- 如果绑定事件处理函数时，没有加小括号，默认会将事件对象作为第一个实参传进去 -->
      <!-- @keyup.enter 只会在敲回车的时候触发事件 -->
    </div>
    <script src="./vue.js"></script>
    <script>
      const app = new Vue({
        el: '#app',
        data: {
          username: '',
        },
        methods: {
          onKeyUp() {
            console.log(this.username);
          },
        },
      });
    </script>
  </body>
</html>
